"""
潮玩宇宙 by hellohjh-压妹蝶---20231119
！！！重要！！！
所有资金盘都不要充值，被骗了别找我
所有资金盘都不要充值，被骗了别找我
所有资金盘都不要充值，被骗了别找我

目前只写了开蛋

微信打开：http://s.jqsjsqb.cn/wx/s?_co=6146281&_st=s&_v=v6
打宝石要实名注册并人脸，位置在---扭蛋兔---打宝石
先人脸完再去模拟器抓包

变量名 cwyzCookie=UID#deviceid#androidid#token，多账号换行
例子     cwyzCookie=446...#ZT46113u...#4abf16...#eyJ0eXAiOi....

游戏版本号搜vesion，填入下面version，例如 version=3.1.1

定时随意，一个小时和半个小时都可以
"""


import os
from urllib.parse import unquote
import time
import random
import base64
import requests
import json
import re
import threading
from notify import send

version='3.1.1'   #游戏版本号
cookies = os.getenv("cwyzCookie")
s=""    #输出推送内容
SendTime=["12","18","23"]     #定时推送，24小时制，开发中



class cwyz:
    def __init__(self, i, cookie):
        self.UID=cookie.split("#")[0]  
        self.deviceid=cookie.split("#")[1]  
        self.androidid=cookie.split("#")[2]  
        self.token=cookie.split("#")[3]  
        
        self.medalNum=0  #勋章
        self.gemNum=0  #矿石
        self.redEnvelope=0  #红包
        self.normalEggNum=0  #普通蛋
        self.medalEggNum=0  #勋章蛋
        self.gemEggNum=0  #宝石蛋
        self.indicate=0 #防止while死循环


#开蛋
    def openEgg(self):
        try:
            url = f"https://android-api.lucklyworld.com/v6/api/nx/open/nd?uid={self.UID}&version={version}"
            headers={
                "Host": "android-api.lucklyworld.com",
                "user-agent": "com.caike.lomo/3.1.1 (Linux; U; Android 10; zh-cn) (official; 301010)",
                "channel": "official",
                "deviceid": self.deviceid,
                "androidid": self.androidid,
                "oaid": "",
                "test-encrypt": "0",
                "uid": "self.uid",
                "token": self.token,
                "content-type": "application/x-www-form-urlencoded",
                "content-length": "0",
                "accept-encoding": "gzip"
            }
            data = {
                'activityId':'1',
                'openType':'1'
            }
            r = requests.post(url,headers=headers, data=data).text
            if re .search ('分解',r ):
                self.discard()
            elif re .search ('替换',r ):
                self.dress()
            else:
                print('开蛋结果异常1：',r)
        except Exception as e:
            print("错误1",e)
            return False
        
#分解装备
    def discard(self):
        try:
            url = f"https://android-api.lucklyworld.com/v6/api/nx/open/discard?uid={self.UID}&version={version}"
            headers={
                "Host": "android-api.lucklyworld.com",
                "user-agent": "com.caike.lomo/3.1.1 (Linux; U; Android 10; zh-cn) (official; 301010)",
                "channel": "official",
                "deviceid": self.deviceid,
                "androidid": self.androidid,
                "oaid": "",
                "test-encrypt": "0",
                "uid": "self.uid",
                "token": self.token,
                "content-type": "application/x-www-form-urlencoded",
                "content-length": "0",
                "accept-encoding": "gzip"
            }
            data = {
                "omType":7,
                "openWinLogId":self.UID
            }
            r = requests.post(url,headers=headers, data=data).json()
            print('分解装备：',r)
        except Exception as e:
            print("错误2",e)
            
#穿上装备
    def dress(self):
        try:
            url = f"https://android-api.lucklyworld.com/v6/api/nx/open/dress?uid={self.UID}&version={version}"
            headers={
                "Host": "android-api.lucklyworld.com",
                "user-agent": "com.caike.lomo/3.1.1 (Linux; U; Android 10; zh-cn) (official; 301010)",
                "channel": "official",
                "deviceid": self.deviceid,
                "androidid": self.androidid,
                "oaid": "",
                "test-encrypt": "0",
                "uid": "self.uid",
                "token": self.token,
                "content-type": "application/x-www-form-urlencoded",
                "content-length": "0",
                "accept-encoding": "gzip"
            }
            data = {
                "openWinLogId":self.UID
            }
            r = requests.post(url,headers=headers, data=data)
            if r.status_code == 200:
                print('穿上装备成功，新战力：',r.json()['warValue'])
        except Exception as e:
            print("错误3",e)
            
            
#获取个人信息
    def userInfo(self,show):
        try:
            url = f"https://android-api.lucklyworld.com/v6/api/nx/index/info?uid={self.UID}&version={version}"
            headers={
                "Host": "android-api.lucklyworld.com",
                "user-agent": "com.caike.lomo/3.1.1 (Linux; U; Android 10; zh-cn) (official; 301010)",
                "channel": "official",
                "deviceid": self.deviceid,
                "androidid": self.androidid,
                "oaid": "",
                "test-encrypt": "0",
                "uid": "self.uid",
                "token": self.token,
                "content-length": "0",
                "accept-encoding": "gzip"
            }
            r = requests.post(url,headers=headers).json()
            self.medalNum=r ['userInfo']['medalNum']#勋章
            self.gemNum=r ['userInfo']['gemNum']#矿石
            self.redEnvelope=r ['userInfo']['redEnvelope']#红包
            self.normalEggNum=r ['eggInfo']['normalEggNum']#普通蛋
            self.medalEggNum=r ['eggInfo']['medalEggNum']#勋章蛋
            self.gemEggNum=r ['eggInfo']['gemEggNum']#宝石蛋
            if show:
                print(f'【勋章】 {self.medalNum}')
                print(f'【矿石】 {self.gemNum}')
                print(f'【红包】 {self.redEnvelope}')
                print(f'【普通蛋】 {self.normalEggNum}')
                print(f'【勋章蛋】 {self.medalEggNum}')
                print(f'【宝石蛋】 {self.gemEggNum}')
        except Exception as e:
            print("错误4",e,r)
            return False
            
#点击红包
    def redbag(self):
        try:
            url = f"https://android-api.lucklyworld.com/v6/api/nx/index/receive/red/envelope?uid={self.UID}&version={version}"
            headers={
                "Host": "android-api.lucklyworld.com",
                "user-agent": "com.caike.lomo/3.1.1 (Linux; U; Android 10; zh-cn) (official; 301010)",
                "channel": "official",
                "deviceid": self.deviceid,
                "androidid": self.androidid,
                "oaid": "",
                "test-encrypt": "0",
                "uid": "self.uid",
                "token": self.token,
                "content-type": "application/x-www-form-urlencoded",
                "content-length": "0",
                "accept-encoding": "gzip"
            }
            r = requests.post(url,headers=headers).json()
            if 'awardProgress' in r:
                print('点击红包成功，当前红包进度（不准，因为看不懂JSON）：',r['awardProgress'])
            else:
                print('领取红包失败',r)
        except Exception as e:
            print("错误5",e)
            
            
#获取每日宝石
    def gemRevenue(self,show):
        try:
            url = f"https://android-api.lucklyworld.com/v6/api/nx/index/gem/revenue?uid={self.UID}&version={version}"
            headers={
                "Host": "android-api.lucklyworld.com",
                "user-agent": "com.caike.lomo/3.1.1 (Linux; U; Android 10; zh-cn) (official; 301010)",
                "channel": "official",
                "deviceid": self.deviceid,
                "androidid": self.androidid,
                "oaid": "",
                "test-encrypt": "0",
                "uid": "self.uid",
                "token": self.token,
                "content-length": "0",
                "accept-encoding": "gzip"
            }
            r = requests.post(url,headers=headers).json()
            predictionTodayRevenue=r ['predictionTodayRevenue'] #每日获得宝石
            allRevenue=r ['allRevenue'] #总获得宝石
            todayRevenue=r ['todayRevenue'] #今日获得宝石

            if show:
                print(f'【每日可获宝石】 {predictionTodayRevenue}')
                print(f'【今日获得宝石】 {allRevenue}')
                print(f'【总获得宝石  】 {todayRevenue}')
        except Exception as e:
            print("错误8",e,r)
            return False
            
            
            
    def run(self):
        self.userInfo(0)

        print('开始开蛋')
        while True:
            #print(int(self.normalEggNum))
            if int(self.normalEggNum)>0:
                self.openEgg()
                self.indicate +=1
                time.sleep(2)
                self.userInfo(0)#更新变量状态，但不打印
            elif self.indicate>100: #执行任务超过100次，退出防止死循环
                break
            else:
                break

        print('所有任务结束')
        self.redbag()
        self.userInfo(1)
        self.gemRevenue(1)


if __name__ == "__main__":
    cookies = cookies.split("\n")
    print('潮玩宇宙！！！')
    print(f"一共获取到{len(cookies)}个账号")
    i = 1
    for cookie in cookies:
        print(f"\n---开始第{i}个账号---")
        cwyz(i,cookie).run()
        i += 1
        print('等待2秒开始下一个账号')
        time.sleep(2)

    #if time.strftime('%H',time.localtime()) in SendTime:
    #s="这是测试2"
    if 0:        
        print("到预定时间，开始推送\n")
        send("潮玩宇宙推送", s)
    else:
        print(s)
        print("未到预定时间，不推送\n")
    
